Skip to content

Comments

Add config file support (init, validate, runtime loading)#203

Open
rdowavic wants to merge 3 commits intoamitsaha:masterfrom
rdowavic:feat/config-file-init
Open

Add config file support (init, validate, runtime loading)#203
rdowavic wants to merge 3 commits intoamitsaha:masterfrom
rdowavic:feat/config-file-init

Conversation

@rdowavic
Copy link

@rdowavic rdowavic commented Feb 20, 2026

Summary

  • Adds gitbackup init subcommand to create a default gitbackup.yml in the current directory
  • Adds gitbackup validate subcommand to check config file values and required environment variables
  • When gitbackup.yml exists, it is automatically loaded at runtime as the base configuration; CLI flags override individual values using fs.Visit() to detect explicitly set flags
  • Adds gitbackup.yml to .gitignore since it's a user-generated file
  • Updates README with a new "Configuration file" section documenting usage

Migration-related flags (-github.createUserMigration, etc.) remain CLI-only. Secrets (tokens, passwords) are never stored in the config file.

Closes #166

Test plan

  • go test ./... passes
  • gitbackup init creates a valid gitbackup.yml with correct defaults
  • gitbackup init errors if file already exists
  • gitbackup validate catches invalid service, invalid repo types, and missing env vars
  • Config file values are loaded at runtime when gitbackup.yml exists
  • CLI flags override config file values
  • No config file behaves exactly as before (no regression)
  • Manual test: gitbackup.yml with service: github + GITHUB_TOKEN runs backup successfully

Add support for a gitbackup.yml configuration file as an alternative to
passing all options as CLI flags. Includes three new capabilities:

- gitbackup init: creates a default gitbackup.yml in the current directory
- gitbackup validate: validates config file values and required env vars
- Runtime loading: when gitbackup.yml exists, it is used as the base
  config with CLI flags overriding individual values

Migration-related flags remain CLI-only. Secrets are always provided
via environment variables and are never stored in the config file.

Closes amitsaha#166
Copy link
Owner

@amitsaha amitsaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @rdowavic couple of things i would like us to address:

  1. Location of the config file - generally, we would follow what other CLI tools do, so, something under the OS specific home/config directory (For e.g. https://github.com/rust-cli/confy/blob/e3e16f7d/README.md#config-file-location). Allow the user to specify a location which then overrides the default location
  2. To achieve the latter of (1), you will need to update the switch case for handling init to also look for the the next arguments. I don't like it, but unfortunately, without a overhaul to use a proper subcommand library, we have to manually parse it.
  3. And if we are doing (2), perhaps also add --help to gitbackup init and gitbackup validate?

If you think we can instead first migrate everything to sub-command driven, we can do that too.

Thoughts?

This is great, and the reason I wanted this support it starts slowly becoming more batch/automated backup process friendly i think.

Address review feedback:

- Store config file in OS-specific config directory instead of the
  current working directory (e.g. ~/.config/gitbackup/gitbackup.yml
  on Linux, ~/Library/Application Support/gitbackup/gitbackup.yml
  on macOS)
- Add --config flag to gitbackup init, validate, and the main command
  to allow specifying a custom config file location
- Add --help support for init and validate subcommands
- Update tests to use explicit config paths instead of os.Chdir
- Update README with new config locations and examples
@rdowavic
Copy link
Author

okay, thanks for the feedback. I'm now using os.UserConfigDir() for the default config location and added in a flag for configuring a custom location. Also added on --help for the subcommands. I think an overhaul for the subcommands is a good idea- use cobra? I'd rather do it in a separate PR once this is merged, does that sound ok?

@amitsaha
Copy link
Owner

amitsaha commented Feb 23, 2026 via email

@rdowavic
Copy link
Author

Okay I've added a new issue #206

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for a config file

2 participants